﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Template.Master"
    Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript" src="/Content/Widget/jquery.fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
    <script type="text/javascript" src="/Content/Widget/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <link rel="stylesheet" type="text/css" href="/Content/Widget/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.css"
        media="screen" />
    <script type="text/javascript">
        function eidtLink(id) {
            window.top.addTab("", "修改友情链接", '<%=Url.Action("Edit") %>' + '?id=' + id, true);
        }
        $(function () {
            var lastIndex;
            $('#tt').datagrid({
                width: 'auto',
                height: '400',
                nowrap: false,
                striped: true,
                remoteSort: false,
                collapsible: true,
                fitColumns: true,
                url: '<%=Url.Action("GetLinkJson") %>',
                sortName: 'Sort',
                sortOrder: 'asc',
                idField: 'Id',
                pagination: true,
                onLoadSuccess: function () {
                    $("a[name=fancybox-link]").fancybox({
                        'overlayShow': false,
                        'transitionIn': 'elastic',
                        'transitionOut': 'elastic',
                        hideOnOverlayClick: true,
                        hideOnContentClick: true

                    });

                },
                columns: [[
                    { field: 'Id', checkbox: true },
                   // { field: 'Code', title: '编号', width: 80 },
                    { field: 'Name', title: '名称', width: 120 },
                    { field: 'Sort', title: '排序', width: 80, sortable: true, editor: { type: 'numberbox', options: { precision: 1}} },
                    { field: 'Image', title: '图片', width: 40, align: 'center', formatter: function (value, rowData, rec) {
                        return '<a name="fancybox-link" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.Image + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/image/easyicon_cn_32.png" /></a>'; ;
                    }
                    },
                    { field: 'IsClosed', title: '停用', width: 80, editor: { type: 'checkbox', options: { on: 'true', off: 'false'} }, formatter: function (value, rec) {

                        return value ? '是' : '否';
                    }
                    },
                    { field: 'OptEdit', title: '修改', width: 80, align: 'center', formatter: function (value, rowData, rec) {
                        return '<span style="color:red" class="jqeasyui-datagrid-edit" onclick="eidtLink(\'' + rowData.Id + '\')" value=' + rowData.Id + '>修改</span>'; ;
                    }
                    }
                ]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        window.top.addTab("", "添加友情链接", '<%=Url.Action("Create") %>');
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var rows = $('#tt').datagrid('getSelections');
                        if (!rows || rows.length == 0) {
                            $.messager.alert('提示', '请选择要删除的数据');
                            return;
                        }
                        var parm;
                        $.each(rows, function (i, n) {
                            if (i == 0) {
                                parm = "id=" + n.Id;
                            }
                            else {
                                parm += "&id=" + n.Id;
                            }
                        });
                        $.messager.confirm('提示', '是否删除这些数据?', function (r) {
                            if (!r) {
                                return;
                            }
                            $.ajax({
                                type: "POST",
                                url: '<%=Url.Action("Delete") %>',
                                data: parm,
                                success: function (msg) {
                                    if (msg.state) {
                                        $.messager.alert('提示', '删除成功！', "info", function () {
                                            $('#tt').datagrid("reload");
                                        });
                                    }
                                },
                                error: function () {
                                    $.messager.alert('错误', '删除失败！', "error");
                                }
                            });
                        });
                    }
                }, '-', {
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        $('#tt').datagrid('acceptChanges');
                    }
                }],
                onBeforeLoad: function () {
                    $(this).datagrid('rejectChanges');
                },
                onClickRow: function (rowIndex) {

                },
                onSelect: function (rowIndex, rowData) {

                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div region="center" style="width: auto; height: 100%; padding: 1px; position: relative;
        overflow-y: auto">
        <table id="tt" style="height: 100%" title="友情链接列表" iconcls="icon-edit">
        </table>
    </div>
</asp:Content>
